package com.qf.service.serviceImpi;

import com.qf.dao.UserDao;
import com.qf.dao.daoimpl.UserDaoImpl;
import com.qf.pojo.User;
import com.qf.service.AdminService;
import com.qf.util.Constants;
import com.qf.util.MD5Utils;

public class AdminServiceImpl implements AdminService {

    @Override
    public User login(String username,String password) {
        UserDao userDao = new UserDaoImpl();
        User user = userDao.FindUserByName(username);
        //判断用户是否存在
        if (user == null) {
            return null;
        }
        //  判断是否为管理员
        if (Constants.ROLE_ADMIN != user.getRole()) {
            return null;
        }
        //判断用户状态
        if (!Constants.USER_ACTIVE.equals(user.getStatus())) {
            return null;
        }
        //判断密码
        String md5PassWord = MD5Utils.md5(password);
        if (user.getPassword().equals(md5PassWord)){
            return  user;
        }
        //其他情况返回false
        return null;
    }
}
